/*
 * @Date: 2025-06-13 10:50:10
 * @Auth: 463997479@qq.com
 * @LastEditors: 463997479@qq.com
 * @LastEditTime: 2025-08-29 15:29:25
 * @FilePath: \corpus\src\pages\Home\AddDeptUser\index.tsx
 */
import { Form, Input, Modal } from 'antd';
import type React from 'react';
import { useEffect } from 'react';
import hooks from '../hooks/useHooks';

const AddDeptUser: React.FC = () => {
  const title = '新增部门用户';

  const { getUser, addUserList, userData, setUserData, addUserVisible, setAddUserVisible } =
    hooks.useContainer();

  const [form] = Form.useForm();

  const handleSubmit = () => {
    form.validateFields().then(async (vals) => {
      console.log(vals);
      const method = addUserList;
      method.run({
        ...vals,
      });
    });
  };
  useEffect(() => {
    if (addUserVisible) {
      form.setFieldsValue({ ...userData });
    }
  }, [addUserVisible, userData]);
  return (
    <Modal
      width={600}
      title={title}
      open={addUserVisible}
      onCancel={() => {
        setAddUserVisible(false);
        setUserData({});
        form.resetFields();
      }}
      onOk={handleSubmit}
    >
      <div style={{ padding: '10.0px' }}>
        <Form labelCol={{ span: 4 }} style={{ marginBottom: '20.0px' }} form={form}>
          <Form.Item label="手机号码" name="mobile" rules={[{ required: true, message: '请选择' }]}>
            <Input
              onPressEnter={(val) => {
                getUser.run(val.target?.value);
              }}
              placeholder="请输入手机号回车查询用户信息"
            />
          </Form.Item>
          <Form.Item
            label="用户姓名"
            name="userName"
            rules={[{ required: true, message: '请选择' }]}
          >
            <Input placeholder="请输入" />
          </Form.Item>

          <Form.Item label="UID" name="accountId">
            <Input disabled placeholder="请输入" />
          </Form.Item>
          <Form.Item name="userName" label="单位">
            <Input disabled placeholder="请输入" />
          </Form.Item>
        </Form>
      </div>
    </Modal>
  );
};

export default AddDeptUser;
